package com.scau.clothes.config;

import com.aliyun.oss.OSSClient;
import com.scau.clothes.storage.AliyunStorage;
import com.scau.clothes.storage.Storage;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "oss.aliyun", name = "active", havingValue = "true")
@ConditionalOnClass(OSSClient.class)
public class AliyunConfiguration {
    @Bean
    @Qualifier("aliyunStorage")
    Storage aliyunStorage(OssProperties ossProperties) {
        OssProperties.Aliyun aliyun = ossProperties.getAliyun();
        OSSClient ossClient = new OSSClient(aliyun.getEndpoint(),
                aliyun.getAccessKeyId(),
                aliyun.getAccessKeySecret());
        return new AliyunStorage(ossClient);
    }
}